package cn.com.roy.thread;

public class Service {
    private String username;
    private String password;
    private String anyString = new String();

    public void setUsernamePassword(String username,String password){
        try{
            synchronized (anyString){
                System.out.println("线程名称：" + Thread.currentThread().getName() + " 在"  + System.currentTimeMillis() + "进入同步块 ");
                this.username = username;
                Thread.sleep(3000);
                this.password = password;
                System.out.println("线程名称：" + Thread.currentThread().getName() + " 在"  + System.currentTimeMillis() + "离开同步块 ");
            }
        }catch(Exception e){
            e.printStackTrace();
        }
    }
}
